package com.daka.entity;

import com.daka.tools.DateUtil;
import lombok.Data;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.type.Alias;

import java.text.ParseException;
import java.util.Date;

@Data
@ToString
@Alias(value = "U_VOLUNTEER_MONEY")
@Slf4j
public class VolunteerMoney {
    /**
     * .
     */
    private Long id;

    /**
     * .
     */
    private Date createTime;

    /**
     * .
     */
    private Integer eventCode;

    /**
     * .
     */
    private Float money;

    /**
     * .
     */
    private Long volunteerId;

    public static VolunteerMoney build(MemberMoneyRecord memberMoneyRecord,Integer volunteerId){
        VolunteerMoney volunteerMoney = new VolunteerMoney();

        Date date;
        try {
            date = DateUtil.str2Date(memberMoneyRecord.getCreatetime(),DateUtil.DATETIME_YYYY_MM_DD_HH_MM_SS);
        } catch (Exception e) {
            date = new Date();
            log.error("===============dakaqi============== Date Format Error! MemberMoneyRecord VolunteerId : " +
                    volunteerId.longValue() + "  EventCode : " +  memberMoneyRecord.getEvent());
        }

        volunteerMoney.setCreateTime(date);
        volunteerMoney.setEventCode(memberMoneyRecord.getEvent());
        volunteerMoney.setMoney(memberMoneyRecord.getMoney());
        volunteerMoney.setVolunteerId(volunteerId.longValue());

        return volunteerMoney;
    }
}